﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyGrid.Core.HexTypeA
{
    ///<summary>方向，具体可见<seealso cref="HexTypeADirectionExtension"/></summary>
    public enum HexTypeADirection
    {
        LeftUp,
        RightUp,
        Right,
        RightDown,
        LeftDown,
        Left,
    }

    ///<summary>方向相关的拓展操作。</summary>
    public static class HexTypeADirectionExtension
    {
        ///<summary>方向的数量。</summary>
        public const int DirectionCount = 6;

        ///<summary>方向是否向左。</summary>
        public static bool IsLeft(this HexTypeADirection direction)
        {
            return direction switch
            {
                HexTypeADirection.LeftUp | HexTypeADirection.LeftDown | HexTypeADirection.Left => true,
                _ => false
            };
        }

        ///<summary>方向是否向右。</summary>
        public static bool IsRight(this HexTypeADirection direction)
        {
            return direction switch
            {
                HexTypeADirection.RightUp | HexTypeADirection.RightDown | HexTypeADirection.Right => true,
                _ => false
            };
        }

        ///<summary>获取所有方向。</summary>
        public static IEnumerable<HexTypeADirection> GetValues()
        {
            return Enum.GetValues(typeof(HexTypeADirection)).OfType<HexTypeADirection>();
        }

        public static HexTypeADirection Reverse(this HexTypeADirection direction)
        {
            int directionEnumValue = (int)direction;
            int reverseDirectionEnumValue = (directionEnumValue + 3) % DirectionCount;
            return (HexTypeADirection)reverseDirectionEnumValue;
        }

        public static HexTypeADirection GetNextClockDirection(this HexTypeADirection direction)
        {
            int directionEnumValue = (int)direction;
            int reverseDirectionEnumValue = (directionEnumValue + 1) % DirectionCount;
            return (HexTypeADirection)reverseDirectionEnumValue;
        }

        public static HexTypeADirection GetNextRClockDirection(this HexTypeADirection direction)
        {
            int directionEnumValue = (int)direction;
            int reverseDirectionEnumValue = (directionEnumValue - 1 + DirectionCount) % DirectionCount;
            return (HexTypeADirection)reverseDirectionEnumValue;
        }

    }
}
